package cn.iocoder.yudao.module.crossborder.platform.dal.mysql.platformstore;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.crossborder.platform.dal.dataobject.platformstore.PlatformStoreDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.crossborder.platform.controller.admin.platformstore.vo.*;

/**
 * 跨境电商店铺管理 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface PlatformStoreMapper extends BaseMapperX<PlatformStoreDO> {

    default PageResult<PlatformStoreDO> selectPage(PlatformStorePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PlatformStoreDO>()
                .eqIfPresent(PlatformStoreDO::getPlatformId, reqVO.getPlatformId())
                .eqIfPresent(PlatformStoreDO::getCode, reqVO.getCode())
                .likeIfPresent(PlatformStoreDO::getName, reqVO.getName())
                .eqIfPresent(PlatformStoreDO::getNameEn, reqVO.getNameEn())
                .eqIfPresent(PlatformStoreDO::getType, reqVO.getType())
                .eqIfPresent(PlatformStoreDO::getPlatformStoreId, reqVO.getPlatformStoreId())
                .eqIfPresent(PlatformStoreDO::getSellerId, reqVO.getSellerId())
                .eqIfPresent(PlatformStoreDO::getMarketplaceId, reqVO.getMarketplaceId())
                .eqIfPresent(PlatformStoreDO::getStoreUrl, reqVO.getStoreUrl())
                .eqIfPresent(PlatformStoreDO::getRegion, reqVO.getRegion())
                .eqIfPresent(PlatformStoreDO::getCurrency, reqVO.getCurrency())
                .eqIfPresent(PlatformStoreDO::getLanguage, reqVO.getLanguage())
                .eqIfPresent(PlatformStoreDO::getTimezone, reqVO.getTimezone())
                .eqIfPresent(PlatformStoreDO::getContactPerson, reqVO.getContactPerson())
                .eqIfPresent(PlatformStoreDO::getContactPhone, reqVO.getContactPhone())
                .eqIfPresent(PlatformStoreDO::getContactEmail, reqVO.getContactEmail())
                .eqIfPresent(PlatformStoreDO::getBusinessLicense, reqVO.getBusinessLicense())
                .eqIfPresent(PlatformStoreDO::getTaxNumber, reqVO.getTaxNumber())
                .eqIfPresent(PlatformStoreDO::getAuthStatus, reqVO.getAuthStatus())
                .betweenIfPresent(PlatformStoreDO::getAuthTime, reqVO.getAuthTime())
                .betweenIfPresent(PlatformStoreDO::getAuthExpireTime, reqVO.getAuthExpireTime())
                .betweenIfPresent(PlatformStoreDO::getLastSyncTime, reqVO.getLastSyncTime())
                .eqIfPresent(PlatformStoreDO::getSyncStatus, reqVO.getSyncStatus())
                .eqIfPresent(PlatformStoreDO::getSyncErrorMsg, reqVO.getSyncErrorMsg())
                .eqIfPresent(PlatformStoreDO::getStatus, reqVO.getStatus())
                .eqIfPresent(PlatformStoreDO::getEnabled, reqVO.getEnabled())
                .eqIfPresent(PlatformStoreDO::getSort, reqVO.getSort())
                .eqIfPresent(PlatformStoreDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(PlatformStoreDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PlatformStoreDO::getId));
    }

    /**
     * 根据平台ID查询店铺列表
     *
     * @param platformId 平台ID
     * @return 店铺列表
     */
    default List<PlatformStoreDO> selectListByPlatformId(Long platformId) {
        return selectList(new LambdaQueryWrapperX<PlatformStoreDO>()
                .eq(PlatformStoreDO::getPlatformId, platformId)
                .eq(PlatformStoreDO::getEnabled, true)
                .orderByDesc(PlatformStoreDO::getId));
    }

    /**
     * 根据平台ID查询已授权的店铺列表
     *
     * @param platformId 平台ID
     * @return 已授权店铺列表
     */
    default List<PlatformStoreDO> selectAuthorizedStoresByPlatformId(Long platformId) {
        return selectList(new LambdaQueryWrapperX<PlatformStoreDO>()
                .eq(PlatformStoreDO::getPlatformId, platformId)
                .eq(PlatformStoreDO::getEnabled, true)
                .eq(PlatformStoreDO::getAuthStatus, 1) // 1-已授权
                .orderByDesc(PlatformStoreDO::getId));
    }

}